<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>  
<html>  
<head>
</head>
<body>
<div class="easyui-layout" data-options="fit:true">  
   <div data-options="region:'west',split:true,border:false,title:'查询'" style="width:225px">
		<form id="fm-query" method="post">  
		<table class="query-table">
			<tbody>
				<tr><td class="ltd">标题:</td><td><input name="title" class="textbox"></td></tr>
				<tr class="operate">
				<td class="ltd"></td>
				<td>
					<a href="#" class="easyui-linkbutton" onclick="js.query()">查询</a>
		            <a href="#" class="easyui-linkbutton" onclick="$('#fm-query').form('clear')">重置</a>
				</td></tr>
			</tbody>
		</table>
	   	</form>  
	</div>  
   <div data-options="region:'center',split:true,border:false,title:'列表'">
    <table id="dg" class="easyui-datagrid" 
            data-options="url:'${ctx}/admin/news/init',singleSelect:true,border:false,collapsible:true,
            fit:true,pagination:true,fitColumns:true,toolbar:'#toolbar',rownumbers:true">  
			    <thead>  
			        <tr>  
						<th field="id" hidden="true">ID</th>
						<th field="title" width="50">标题</th>
						<th field="createDate" width="50">创建日期</th>
						<th field="modifyDate" width="50">更新日期</th>
			        </tr>  
			    </thead>  
			</table>
			<div id="toolbar">
			    <a href="#" class="easyui-linkbutton" plain="true" onclick="js.add()" enabled="function.add">新增</a>
			    <a href="#" class="easyui-linkbutton" plain="true" onclick="js.edit()"  enabled="function.edit">编辑</a>
			    <a href="#" class="easyui-linkbutton" plain="true" onclick="js.remove()"  enabled="function.delete">删除</a>
			</div>  
			<div id="dlg" class="easyui-dialog" style="width:800px;height:550px;padding: 10px;" closed="true" buttons="#dlg-buttons">
			<form id="fm" method="post">    
		        <table class="dlg-table" style="width:746px;">
		        	<tbody>
		        		<tr><td class="ltd">公告标题:</td><td class="rtd"><input name="title" style="width: 575px;"><input name="id" type="hidden"></td></tr>
		        		<tr><td class="ltd">公告内容:</td><td class="rtd"></td></tr> 
		        		<tr>
		        			<td colspan="2">
		        				<textarea id="content" name="content" style="width:300px;height: 100px;"></textarea>
		        			</td>
					   	</tr>
		        	</tbody>
		        </table>
		    </form>  
			</div>  
			<div id="dlg-buttons">  
			    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="js.save()">确定</a>  
			    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>  
			</div>  
	</div>  
</div>
<script type="text/javascript">
	$('#content').ckeditor();
	var url="${ctx}/admin/news";
	
	js.add=function(){  
	    $('#dlg').dialog('open').dialog('setTitle','新增');  
	    $('#fm').form('clear');  
	    $('#content').ckeditor("clear");
	};
	
	js.edit=function(){  
		var row = $('#dg').datagrid('getSelected');  
		$('#fm').form('clear');  
		if (row){  
			$('#content').ckeditor("clear");
		    $.post("${ctx}/admin/news/"+row.id,function(news){
		    	$('#fm').form('load',news);  	
		    	$('#content').ckeditor("setValue",news.content);
		    });
		    $('#dlg').dialog('open').dialog('setTitle','编辑');  
		}  
	};
	
	
	js.save=function(){  
		$('#content').ckeditor("sync");
	    $('#fm').form('submit',{  
	        url: url+"/save",  
	        onSubmit: function(){  
	            return $(this).form('validate');  
	        },  
	        success: function(result){  
	        	result=js.json(result);
	            if (result.success){  
	                $('#dlg').dialog('close');  
	                $('#dg').datagrid('load');  
	            } else {  
	                $.messager.show({  
	                    title: '信息反馈',  
	                    msg: result.msg  
	                });  
	            }  
	        }  
	    });  
	};
	
	js.remove=function(){  
	    var row = $('#dg').datagrid('getSelected');  
	    if (row){  
	        $.messager.confirm('消息框','确定要删除吗?',function(r){  
	            if (r){  
	                $.post(url+'/delete',{id:row.id},function(result){ 
	                    if (result.success){  
	                        $('#dg').datagrid('load');
	                    } else {  
	                        $.messager.show({  
	                            title: '信息反馈',  
	                            msg: result.msg  
	                        });  
	                    }
	                });  
	            }  
	        });  
	    }  
	};
	
	js.query=function(){ 
	   var params=$('#fm-query').serializeObject();
	   $('#dg').datagrid({url:url,queryParams:params,pageNumber:1});
	};
	</script>
</body>
</html>
